import Angle from './Angle';
import Point from './Point';

/** 向量线计算类 */
export default class Vector {

	/** 开始点 */
	private start: Point;

	/** 结束点 */
	private end: Point;

	/** 角度 */
	private angle: Angle;

	/** 长度 */
	private length: number;

	/** 开始点 */
	public get Start(): Point {
		return this.start;
	}

	/** 结束点 */
	public get End(): Point {
		return this.end;
	}

	/** 角度 */
	public get Angle(): Angle {
		return this.angle;
	}

	/** 长度 */
	public get Length(): number {
		return this.length;
	}
	public set Length(val: number) {
		this.length = val;
	}

	/**
	 * 构造函数
	 * @param start 开始点
	 * @param angle 角度
	 * @param length 长度
	 */
	public constructor(start: Point, angle: Angle, length: number) {
		this.start = start;
		this.angle = angle;
		this.length = length;
		this.end = start.Move(length, 0).Rotate(start, angle);
	}

	/**
	 * 移动
	 * @param X x移动距离
	 * @param Y y移动距离
	 */
	public Move(X: number, Y: number): Vector {
		const start = this.start.Move(X, Y);
		return new Vector(start, this.angle, this.length);
	}

	/** 前往 */
	public To(): Vector {
		const start = this.End.Move(0, 0);
		return new Vector(start, this.angle, this.length);
	}

	/** 前往一点距离 */
	public ToLength(length: number): Vector {
		const ret = new Vector(this.start, this.angle, length);
		return ret.To().SetLength(this.Length);
	}

	/**
	 * 旋转
	 * @param angle 旋转角度
	 */
	public Rotate(angle: Angle) {
		angle.Angle += this.angle.Angle;
		return new Vector(this.start, angle, this.length);
	}

	/**
	 * 旋转
	 * @param angle 旋转角度
	 */
	public RotateAngle(angle: number) {
		angle += this.angle.Angle;
		return new Vector(this.start, new Angle(angle), this.length);
	}

	/**
	 * 添加长度
	 * @param length 添加的长度
	 */
	public AddLength(length: number) {
		length += this.length;
		return new Vector(this.start, this.angle, length);
	}

	/**
	 * 设置长度
	 * @param length 添加的长度
	 */
	public SetLength(length: number) {
		return new Vector(this.start, this.angle, length);
	}

}
